// import { CodeBuilder } from "../Code/CodeBuilder";
// import { Graph } from "../graph/graph";
// import { AstNode } from "../compile/Ast";
// import { oProject } from "../Project";
// import lodash from 'lodash'

// export class TrainerTrigger {
//   /**
//    *
//    */
//   constructor(
//     public key: string = '',
//     public graphName: string = '',
//   ) {}

//   public static compileAll(triggers: TrainerTrigger[]): string {

//     const builder = new CodeBuilder()
//     builder.add(`TARGET_NAME = '${oProject.value.gameTitle}'`)
//     builder.add(`from pynput import keyboard`)
//     builder.add(Graph.PRE)

//     // 编译所有图
//     oProject.value.graphs.forEach(graph => {
//       const ast = AstNode.parse(graph)
//       const appCode = ast.compile()
//       builder.addFunction(graph.name, [], appCode)
//     })

//     const TAB = '  '
//     const trigerCode = triggers.map(trigger => {
//       const graph = oProject.value.graphs.find(x => x.name === trigger.graphName)!
//       console.log('graph', graph);
//       console.log('trigger.graphName', trigger.graphName);
//       console.log('oProject.value.graphs', oProject.value.graphs);
//       const execCode = `${graph.name}()`
//       const conditionCode = `${TAB}${TAB}if key.char == "${trigger.key}":\n`
//       return `${conditionCode}${TAB}${TAB}${TAB}${execCode}`
//     }).join('\n')

//     const appCode = `\
// def on_press(key):
//   try:
//     print(f'按下按键：{key.char}')
// ${trigerCode}

//   except AttributeError:
//     pass

// process__ = keyboard.Listener(on_press=on_press)
// `
    
    
    
//     builder.add(appCode)
//     return builder.build()
//   }

//   public static deserialize(param: any): TrainerTrigger {
//     if (Object.prototype.toString.call(param) === '[object String]') {
//       return this.deserialize(JSON.parse(param))
//     }
//     else {
//       const obj = new TrainerTrigger()
//       lodash.assign(obj, param)

//       // 对于复杂成员，调用成员类的反序列化
//       // obj.graph = Graph.deserialize(obj.graph)
//       return obj
//     }
//   }

//   public static deserializeArray(obj: any): TrainerTrigger[] {
//     return (obj as any[]).map(x => this.deserialize(x)) as TrainerTrigger[]
//   }
// }